package com.store;

import java.sql.Date;

import com.jedi.BaseObj;
import com.tss.util.DbConn;
import com.tss.util.DbRs;

public class Pala extends BaseObj {
public Pala(){}
	public void insert() {

		clearErr();
		DbConn conn = new DbConn();
		try {
			conn.setAutoCommit(false);
			
			
			String sql = "";
			DbRs rs = null;
			sql = "select * from pala where conid = ?";
			conn.prepare(sql);
			conn.setInt(1,getConid());
			rs = conn.executeQuery();
			if (rs != null && rs.size() > 0) {
				setErr("此合同已经做过损益分析");
				return;
			}
			 sql = "insert into pala(conid,createman,y,m) values(?,?,?,?)";
			conn.prepare(sql);
			conn.setInt(1, getConid());
			//conn.setDouble(2, getSpartfee());
			//conn.setDouble(3, getOutefee());
			conn.setString(2, getCreateman());
			conn.setInt(3, getY());
			conn.setInt(4, getM());
			conn.executeUpdate();
			conn.commit();
		} catch (Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			try {
				conn.rollback();
			} catch (Exception e) {
				e.printStackTrace();
			}
		} finally {
			conn.close();
		}
	}
	
	public boolean isAnalysis(int conid) {

		clearErr();
		DbConn conn = new DbConn();
		try {
	
			String sql = "";
			DbRs rs = null;
			sql = "select * from pala where conid = ?";
			conn.prepare(sql);
			conn.setInt(1,conid);
			rs = conn.executeQuery();
			if (rs.size()>0) {
				//setErr("此工单已经做过损益分析");
				return true;
			}

		} catch (Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			try {
			
			} catch (Exception e) {
				e.printStackTrace();
			}
		} finally {
			conn.close();
		}
		return false;
	}
	
	public void update() {
		clearErr();
		DbConn conn = new DbConn();

		try {
			conn.setAutoCommit(false);
			String sql = "update pala  set spartfee=?,outefee=?,createman=?,y=?,m =? where conid=?";
			conn.prepare(sql);
			conn.setDouble(1, getSpartfee());
			conn.setDouble(2, getOutefee());
			conn.setString(3, getCreateman());  
			conn.setInt(4, getY());
			conn.setInt(5, getM());
			conn.setInt(6,getConid());
			conn.executeUpdate();
			conn.commit();
		} catch (Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());

		} finally {
			conn.close();
		}
	}
///////////////////////////////////////////////////////////////////////////////////////////
	public Pala(String id){
		this.id=id;
	}
	
	private String id="";
	
	private	int y = 0;// NOT NULL DEFAULT date_part('year'::text,('now'::text)::date), -- 核算年

	private    int m = 0;// NOT NULL DEFAULT date_part('month'::text,- 核算月

	private	int conid = 0;// NOT NULL, -- 合同编号

	private	double spartfee = 0.00;// numeric(12,2) DEFAULT 0, -- 备件成本

	private	double outefee = 0.00;// numeric(12,2) DEFAULT 0, -- 外部人员技术成本

	private	Date createtime = null;// DEFAULT now(), -- 创建时间

	private	String createman = "";// varchar(20), -- 创建人

	public int getConid() {
		return conid;
	}

	public void setConid(int conid) {
		this.conid = conid;
	}

	public String getCreateman() {
		return createman;
	}

	public void setCreateman(String createman) {
		this.createman = createman;
	}

	public Date getCreatetime() {
		return createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getM() {
		return m;
	}

	public void setM(int m) {
		this.m = m;
	}

	public double getOutefee() {
		return outefee;
	}

	public void setOutefee(double outefee) {
		this.outefee = outefee;
	}

	public double getSpartfee() {
		return spartfee;
	}

	public void setSpartfee(double spartfee) {
		this.spartfee = spartfee;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

}
